-- @owner: @zou_jialiang050
-- @date: 2023/2/20
-- @testpoint: create function 使用原有语句创建包含while控制语句函数

--step1:建表插数据;expect:成功
drop table if exists t_create_function_0037;
create table t_create_function_0037(cid int);

--step2:create function 使用原有语句创建包含while控制语句函数;expect:成功
drop function if exists f_create_function_0037;
create function f_create_function_0037(card_id int) returns char(50) as
$$
declare num int := 0;
begin
while num<=card_id loop
insert into t_create_function_0037 values(num);
num := num+1;
end loop;
return card_id;
end;
$$ language plpgsql;
/

select f_create_function_0037(3);
select * from t_create_function_0037;

--step3:清理环境;expect:成功
drop function if exists f_create_function_0037;
drop table if exists t_create_function_0037;